<?php
class Login extends CI_Controller {

    public function __construct(){
		parent::__construct();
    }
    
    function index(){
		$data['errortext'] = "";
		$this->load->view("login/v_login",$data);
    }
    
    function proses()
    {
		$data['errortext'] = "";
		$rules['username']	= "required|min_length[4]|max_length[30]|alpha_dash";
		$rules['password']	= "required|min_length[4]|max_length[30]|alpha_dash";
		$this->validation->set_rules($rules);
	
		$fields['username'] = 'username';
		$fields['password'] = 'password';
		$this->validation->set_fields($fields);
	
		if ($this->validation->run() == FALSE)
		{
			$data['errortext'] = $this->validation->error_string;
			$this->load->view('login/v_login',$data);
		}
		else
		{
			if ($this->authlogin->login($this->input->post('username'), $this->input->post('password'))==1) {
				redirect('home');
			} else {
				$data['errortext'] = '<p>Your username/password combination is incorrect. Please try again.</p>';
				$this->load->view('login/v_login',$data);
			}
		}      
    }

    function logout()
    {
		$this->authlogin->logout();
		redirect('login');
    }
}
